<?php
/**
 * @author jiangyong<jiangyong.go@qq.com>
 * @date   2025/5/23 09:19
 */

namespace App\Http\Controllers\My;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Spatie\RouteAttributes\Attributes\Any;
use Spatie\RouteAttributes\Attributes\Middleware;
use Spatie\RouteAttributes\Attributes\Prefix;

#[Prefix('my/login')]
#[Middleware(['web'])]   /**\Illuminate\Session\Middleware\StartSession::class **/
class LoginController extends Controller
{
    #[Any('/'), middleware(['auth:web'])]
    public function index()
    {
        $data['is_login'] = auth()->check();
        $data['user'] = auth()->user();

        // 调试信息
        \Log::info('Login Debug', [
            'session_isStarted' => session()->isStarted(),
            'session_id' => session()->getId(),
            'auth_check_immediate' => Auth::check(),
            'auth_user_immediate' => Auth::user()?->id,
            'session_data' => session()->all()
        ]);

        return $data;
    }

    #[Any('login')]
    public function login()
    {
        $data['login'] = auth()->loginUsingId(1);
        $data['user'] = auth()->user();

        // 调试信息
        \Log::info('Login Debug', [

            'session_id' => session()->getId(),
            'auth_check_immediate' => Auth::check(),
            'auth_user_immediate' => Auth::user()?->id,
            'session_data' => session()->all()
        ]);
        return $data;
    }
}
